﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class cn_feedback4 : System.Web.UI.Page
{
    protected string _cid = "19"; protected string parentId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        _cid = Request.QueryString["cid"]; parentId = Request.QueryString["parentId"];
        if (string.IsNullOrEmpty(_cid))
        {
            _cid = ColumnHelp.GetFirstColumnId(16);
        }
        else
        {
            if (!Whir.Common.WebHelper.Utils.IsInt(_cid))
                _cid = ColumnHelp.GetFirstColumnId(16);
        }
       
        if (!IsPostBack)
        {
            GetTipsInfo(); GetBindDdl();
            if (Session["UserName"] != null)
            {

                GetInfo();
            }
            
        }
    }

    private void GetBindDdl()
    {
        DropDownList1.Items.Clear();
        DropDownList1.Items.Add(new ListItem("--请选择--","0"));
        string sql="select * from Whir_CommonCategory where ParentId=1";
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        foreach (DataRow dr in dt.Rows)
        {
            DropDownList1.Items.Add(new ListItem(dr["CategoryName"].ToString(), dr["CategoryId"].ToString()));
        }

        DropDownList2.Items.Clear();
        DropDownList2.Items.Add(new ListItem("--请选择--", "0"));
        string sql2 = "select * from Whir_CommonCategory where ParentId=2";
        DataTable dt2 = Whir.SQLServerDAL.DbHelperSQL.Query(sql2).Tables[0];
        foreach (DataRow dr2 in dt2.Rows)
        {
            DropDownList2.Items.Add(new ListItem(dr2["CategoryName"].ToString(), dr2["CategoryId"].ToString()));
        }

    }

    private void GetInfo()
    {
        string sql = string.Format("select * from Whir_U_Users where LoginName='{0}' ", Session["UserName"].ToString());
        DataTable dt = Whir.SQLServerDAL.DbHelperSQL.Query(sql).Tables[0];
        if (dt != null && dt.Rows.Count > 0)
        {

            txtName.Value = dt.Rows[0]["TrueName"].ToString();
            txtTel.Value = dt.Rows[0]["LinkTel"].ToString();
            txtCompanyAddress.Value = dt.Rows[0]["Address"].ToString();
            txtWebSiteUrl.Value = dt.Rows[0]["WebSiteUrl"].ToString();
            txtFax.Value = dt.Rows[0]["Fax"].ToString();
            txtCompanyTel.Value = dt.Rows[0]["CompanyTel"].ToString();
            txtCompanyFax.Value = dt.Rows[0]["CompanyFax"].ToString();
            txtMobile.Value = dt.Rows[0]["Mobie"].ToString();


            txtProducts.Value = dt.Rows[0]["Products"].ToString();            
            txtZCZZ.Value = dt.Rows[0]["NewC"].ToString();
            txtNLS.Value = dt.Rows[0]["NLS"].ToString();
            txtNCZ.Value = dt.Rows[0]["NewD"].ToString();
            
            DropDownList1.SelectedValue = dt.Rows[0]["NewI"].ToString();
            DropDownList2.SelectedValue = dt.Rows[0]["characteristic"].ToString();
            RadioButtonList1.SelectedValue = dt.Rows[0]["zscq"].ToString();


            txtCompanyName.Value = dt.Rows[0]["NewH"].ToString();
        }

    }
    private void GetTipsInfo()
    {
        ltrTips.Text = ColumnHelp.GetColumnName(_cid);
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {

        //string sex="女";
        //if(Sex1.Checked==true)
        //    sex="男";
        //else
        //    sex="女";



        string IsUser = "否",username="";
        if (Session["UserName"] != null)
        {
            IsUser = "是";
            username = Session["UserName"].ToString();
        }

        string FilePath = "";
        string url = Request.Url.Host;

        if (InputFile1.HasFile)
        {
            string path = Page.Server.MapPath(Whir.Common.Settings.GetSystemPath() + "/UploadFiles");
            string destPath = System.IO.Path.Combine(path, InputFile1.FileName);
            this.InputFile1.MoveTo(destPath, Brettle.Web.NeatUpload.MoveToOptions.Overwrite);

            FilePath = url + Whir.Common.Settings.GetSystemPath() + "UploadFiles/" + InputFile1.FileName;
        }


        string sql = "insert into Whir_U_Message (TypeID,CreateDate,WebSiteUrl,CompanyAddress,CompanyTel,CompanyFax,remarks,enclosure,Person,Tel,Fax,Mobie,NewH,NewI,characteristic,NewD,NLS,NewC,zscq,Products,IsUser,UserName) values (@TypeID,@CreateDate,@WebSiteUrl,@CompanyAddress,@CompanyTel,@CompanyFax,@remarks,@enclosure,@Person,@Tel,@Fax,@Mobie,@NewH,@NewI,@characteristic,@NewD,@NLS,@NewC,@zscq,@Products,@IsUser,@UserName)";
        SqlParameter[] pa =
        {
            new SqlParameter("@TypeID",_cid),
            new SqlParameter("@CreateDate",DateTime.Now),
            new SqlParameter("@WebSiteUrl",txtWebSiteUrl.Value),
            new SqlParameter("@CompanyAddress",txtCompanyAddress.Value),
            new SqlParameter("@CompanyTel",txtCompanyTel.Value),
            new SqlParameter("@CompanyFax",txtCompanyFax.Value),
            new SqlParameter("@remarks",txtRemarks.Value),
            new SqlParameter("@enclosure",FilePath),
            new SqlParameter("@Person",txtName.Value),
            new SqlParameter("@Tel",txtTel.Value),
            new SqlParameter("@Fax",txtFax.Value),
            new SqlParameter("@Mobie",txtMobile.Value),

            new SqlParameter("@NewH",txtCompanyName.Value),                                         //单位名称
            new SqlParameter("@NewI",DropDownList1.SelectedValue),                      //单位类型
            new SqlParameter("@characteristic",DropDownList2.SelectedValue),            //单位特性
            new SqlParameter("@NewD",txtNCZ.Value),                                     //年产值（万元）
            new SqlParameter("@NLS",txtNLS.Value),                                      //年利税
            new SqlParameter("@NewC",txtZCZZ.Value),                                    //注册资金（万元）
            new SqlParameter("@zscq",RadioButtonList1.SelectedValue),                   //是否拥有知识产权
            new SqlParameter("@Products",txtProducts.Value) ,                            //主营产品
            new SqlParameter("@IsUser",IsUser), 
            new SqlParameter("@UserName",username)
            
        };
        int count = Whir.SQLServerDAL.DbHelperSQL.ExecuteSql(sql, pa);
        if (count > 0)
        {

            Whir.Common.WebHelper.JsHelper.redirect(this.Page, "发送成功!", "feedback4.aspx?cid=" + _cid + "&parentId=" + parentId);


        }
        else { Whir.Common.WebHelper.JsHelper.Alert(this.Page, "发送失败!"); }
    }
}
